from src.common.logger import getLogger
from src.agentic.agent.AgentTools import AgentTools
from src.agentic.config.LanguageModel import LanguageModel
from src.agentic.agent.program.TopicAgent import TopicAgent
from src.modules.memory.service import HistoryRecordService, MemoryDetailService

logger = getLogger()

def invoke_report(args):

    HistoryRecordService.insert_history_memory(args)

    llm_model = LanguageModel("qwen3:4b", "http://localhost:11434", None).new_llm_model()

    agent_tools = AgentTools().get_execute_tools()

    query = args.get("query")
    logger.info(f"invoke_report query: {query}")

    agent = TopicAgent(llm_model, agent_tools)
    response = agent.invoke(query)

    MemoryDetailService.insert_memory_detail_ai(args, response)

    logger.info(f"invoke_report response len: {len(response)}")
    return response
